﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SqlHelperForCry.Common;
using Torch.WL.Entity;

namespace Torch.WL.Web.CleanChina
{
    public partial class aboutExpo : BasePage
    {
        protected int expoId
        {
            get
            {
                int expoId = 1;
                if (!int.TryParse(Request["ExpoId"], out expoId))
                    expoId = 1;
                return expoId;
            }

        }

        private string imageUrl
        {
            get
            {
                if (ViewState["WebsiteImageUrl"] == null)
                    ViewState["WebsiteImageUrl"] = AppSettingsHelper.GetString("WebsiteImageUrl");
                string url = ViewState["WebsiteImageUrl"].ToString();
                return url;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }

        }

        protected void LoadData()
        {
            Tb_Expo currentExpo = new Tb_Expo(expoId);
            currentExpo.Load();
            this.txtZhmc.Text = currentExpo.expoName;
            this.txtZhsj.Text = currentExpo.beginDate.ToString("yyyy-MM-dd");
            this.txtZhsj2.Text = currentExpo.endDate.ToString("yyyy-MM-dd");
            this.txtZhdd.Text = currentExpo.address;
            this.txtWz.Text = currentExpo.website;
            this.txtZhjj.Text = currentExpo.summary;

            if (!string.IsNullOrEmpty(currentExpo.logo))
            {
                this.ltZhlogo.Text = "<a onmouseout='HideThumb()' onmouseover=\"ShowThumb('" + currentExpo.logo + "')\" ><img src='" + imageUrl + "\\" + currentExpo.logo + "' style='border:none;width:20px;height:20px;'  /></a>";
            }



            if (!string.IsNullOrEmpty(currentExpo.howtoVisit))
            {
                this.ltRhcg.Text = "<a onmouseout='HideThumb()' onmouseover=\"ShowThumb('" + currentExpo.howtoVisit + "')\" ><img src='" + imageUrl + "\\" + currentExpo.howtoVisit + "' style='border:none;width:20px;height:20px;'  /></a>";
            }
            if (!string.IsNullOrEmpty(currentExpo.JiuDianZS))
            {
                this.ltJdzs.Text = "<a onmouseout='HideThumb()' onmouseover=\"ShowThumb('" + currentExpo.JiuDianZS + "')\" ><img src='" + imageUrl + "\\" + currentExpo.JiuDianZS + "' style='border:none;width:20px;height:20px;'  /></a>";
            }
            if (!string.IsNullOrEmpty(currentExpo.MianFeiBC))
            {
                this.ltMfbc.Text = "<a onmouseout='HideThumb()' onmouseover=\"ShowThumb('" + currentExpo.MianFeiBC + "')\" ><img src='" + imageUrl + "\\" + currentExpo.MianFeiBC + "' style='border:none;width:20px;height:20px;'  /></a>";
            }
            if (!string.IsNullOrEmpty(currentExpo.TingCheFW))
            {
                this.ltTcfw.Text = "<a onmouseout='HideThumb()' onmouseover=\"ShowThumb('" + currentExpo.TingCheFW + "')\" ><img src='" + imageUrl + "\\" + currentExpo.TingCheFW + "' style='border:none;width:20px;height:20px;'  /></a>";
            }



            if (!string.IsNullOrEmpty(currentExpo.CanYin))
            {
                this.ltCy.Text = "<a onmouseout='HideThumb()' onmouseover=\"ShowThumb('" + currentExpo.CanYin + "')\" ><img src='" + imageUrl + "\\" + currentExpo.CanYin + "' style='border:none;width:20px;height:20px;'  /></a>";
            }
            if (!string.IsNullOrEmpty(currentExpo.WangLuo))
            {
                this.ltWl.Text = "<a onmouseout='HideThumb()' onmouseover=\"ShowThumb('" + currentExpo.WangLuo + "')\" ><img src='" + imageUrl + "\\" + currentExpo.WangLuo + "' style='border:none;width:20px;height:20px;'  /></a>";
            }
            if (!string.IsNullOrEmpty(currentExpo.XiShouJ))
            {
                this.ltXsj.Text = "<a onmouseout='HideThumb()' onmouseover=\"ShowThumb('" + currentExpo.XiShouJ + "')\" ><img src='" + imageUrl + "\\" + currentExpo.XiShouJ + "' style='border:none;width:20px;height:20px;'  /></a>";
            }
            if (!string.IsNullOrEmpty(currentExpo.LiPin))
            {
                this.ltLp.Text = "<a onmouseout='HideThumb()' onmouseover=\"ShowThumb('" + currentExpo.LiPin + "')\" ><img src='" + imageUrl + "\\" + currentExpo.LiPin + "' style='border:none;width:20px;height:20px;'  /></a>";
            }
            if (!string.IsNullOrEmpty(currentExpo.ZhuBanFBGS))
            {
                this.ltZbfbgs.Text = "<a onmouseout='HideThumb()' onmouseover=\"ShowThumb('" + currentExpo.ZhuBanFBGS + "')\" ><img src='" + imageUrl + "\\" + currentExpo.ZhuBanFBGS + "' style='border:none;width:20px;height:20px;'  /></a>";
            }
            if (!string.IsNullOrEmpty(currentExpo.VIPXXQ))
            {
                this.ltVipxxs.Text = "<a onmouseout='HideThumb()' onmouseover=\"ShowThumb('" + currentExpo.VIPXXQ + "')\" ><img src='" + imageUrl + "\\" + currentExpo.VIPXXQ + "' style='border:none;width:20px;height:20px;'  /></a>";
            }


            Tb_Advertise ad = new Tb_Advertise();
            if (ad.Load("adv_isCurrent=1"))
            {
                this.imgDqtp.Src = imageUrl + "\\" + ad.adv_img;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string msg = "";
            Tb_Expo currentExpo = new Tb_Expo(expoId);
            currentExpo.Load();
            currentExpo.expoName = this.txtZhmc.Text;
            DateTime dtBegin;
            DateTime dtEnd;
            if (DateTime.TryParse(this.txtZhsj.Text, out dtBegin))
                currentExpo.beginDate = dtBegin;
            if (DateTime.TryParse(this.txtZhsj2.Text, out dtEnd))
                currentExpo.endDate = dtEnd;
            currentExpo.address = this.txtZhdd.Text;
            currentExpo.website = this.txtWz.Text;
            currentExpo.summary = this.txtZhjj.Text;
            currentExpo.Save();

            string fileName = "";
            if (!WebCommon.UploadFile(this.fuZhlogo, out fileName, out msg))
            {
                WebCommon.ShowMessage(this, msg);
            }
            else
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    #region 写数据库
                    currentExpo.logo = fileName;
                    currentExpo.Save();
                    #endregion
                }
            }

            if (!WebCommon.UploadFile(this.fuRhcg, out fileName, out msg))
            {
                WebCommon.ShowMessage(this, msg);
            }
            else
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    #region 写数据库
                    currentExpo.howtoVisit = fileName;
                    currentExpo.Save();
                    #endregion
                }
            }

            if (!WebCommon.UploadFile(this.fuJdzs, out fileName, out msg))
            {
                WebCommon.ShowMessage(this, msg);
            }
            else
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    #region 写数据库
                    currentExpo.JiuDianZS = fileName;
                    currentExpo.Save();
                    #endregion
                }
            }

            if (!WebCommon.UploadFile(this.fuMfbc, out fileName, out msg))
            {
                WebCommon.ShowMessage(this, msg);
            }
            else
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    #region 写数据库
                    currentExpo.MianFeiBC = fileName;
                    currentExpo.Save();
                    #endregion
                }
            }

            if (!WebCommon.UploadFile(this.fuTcfw, out fileName, out msg))
            {
                WebCommon.ShowMessage(this, msg);
            }
            else
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    #region 写数据库
                    currentExpo.TingCheFW = fileName;
                    currentExpo.Save();
                    #endregion
                }
            }

            if (!WebCommon.UploadFile(this.fuCy, out fileName, out msg))
            {
                WebCommon.ShowMessage(this, msg);
            }
            else
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    #region 写数据库
                    currentExpo.CanYin = fileName;
                    currentExpo.Save();
                    #endregion
                }
            }

            if (!WebCommon.UploadFile(this.fuWl, out fileName, out msg))
            {
                WebCommon.ShowMessage(this, msg);
            }
            else
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    #region 写数据库
                    currentExpo.WangLuo = fileName;
                    currentExpo.Save();
                    #endregion
                }
            }

            if (!WebCommon.UploadFile(this.fuXsj, out fileName, out msg))
            {
                WebCommon.ShowMessage(this, msg);
            }
            else
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    #region 写数据库
                    currentExpo.XiShouJ = fileName;
                    currentExpo.Save();
                    #endregion
                }
            }

            if (!WebCommon.UploadFile(this.fuLp, out fileName, out msg))
            {
                WebCommon.ShowMessage(this, msg);
            }
            else
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    #region 写数据库
                    currentExpo.LiPin = fileName;
                    currentExpo.Save();
                    #endregion
                }
            }

            if (!WebCommon.UploadFile(this.fuZbfbgs, out fileName, out msg))
            {
                WebCommon.ShowMessage(this, msg);
            }
            else
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    #region 写数据库
                    currentExpo.ZhuBanFBGS = fileName;
                    currentExpo.Save();
                    #endregion
                }
            }

            if (!WebCommon.UploadFile(this.fuVipxxs, out fileName, out msg))
            {
                WebCommon.ShowMessage(this, msg);
            }
            else
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    #region 写数据库
                    currentExpo.VIPXXQ = fileName;
                    currentExpo.Save();
                    #endregion
                }
            }

            if (!WebCommon.UploadFile(this.fuGhtp, out fileName, out msg))
            {
                WebCommon.ShowMessage(this, msg);
            }
            else
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    #region 写数据库
                    DataAccess.Update(typeof(Tb_Advertise), "adv_isCurrent=0", "adv_isCurrent=1");

                    Tb_Advertise ad = new Tb_Advertise();
                    ad.adv_title = "";
                    ad.adv_isCurrent = 1;
                    ad.adv_img = fileName;
                    ad.createTime = DateTime.Now;
                    ad.Save();
                    #endregion
                }
            }
            LoadData();
            WebCommon.ShowMessage(this, "已成功保存！");
        }


    }
}